package testes;


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.util.Collection;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import org.jdom.Element;

/**
 * 
 * @author luciano
 */
public class MyTableModel extends AbstractTableModel {

	private Vector<Element> elements = new Vector<Element>();
	private String[] titles = { "Nome" };

	
	public MyTableModel() {
		
	}
	
	public MyTableModel(Vector<Element> elements, String[] titles) {
		this.elements = elements;
		if (titles != null)
			this.titles = titles;
	}

	public void setRegras(Collection<Element> elements) {
		this.elements.removeAllElements();
		this.elements.addAll(elements);
		fireTableStructureChanged();
	}

	public void setElement(Vector<Element> elements) {
		this.elements = elements;
		fireTableStructureChanged();
	}

	public Vector<Element> getElements() {
		return elements;
	}

	public int getRowCount() {
		return this.elements.size();
	}

	public int getColumnCount() {
		return this.titles.length;
	}

	@Override
	public boolean isCellEditable(int rowIndex, int columnIndex) {
		return (columnIndex == 3) || (columnIndex == 2);
	}

	@Override
	public void setValueAt(Object aValue, int rowIndex, int columnIndex) {

		if (columnIndex == 0) {
			if (aValue instanceof Boolean)
				;//regras.get(rowIndex).setEleito((Boolean) aValue);
		}
		fireTableCellUpdated(rowIndex, columnIndex);
	}

	public Object getValueAt(int rowIndex, int columnIndex) {
		return elements.get(rowIndex);
	}

	public void addElement(Element element) {
		if (!elements.contains(element))
			elements.add(element);
		fireTableDataChanged();
	}

	public void remRegra(Element element) {
		if (elements.contains(element))
			elements.remove(element);
		fireTableDataChanged();
	}

	public Element getElementeAt(int index) {
		return elements.get(index);
	}

	public void remRegraAt(int index) {
		elements.remove(index);
		fireTableDataChanged();
	}

	public void removeAll(int[] sels) {
		for (int i = sels.length - 1; i >= 0; i--) {
			elements.remove(sels[i]);
			fireTableDataChanged();
		}
	}

	@Override
	public Class<?> getColumnClass(int column) {
		return getValueAt(0, column).getClass();
	}

	@Override
	public String getColumnName(int column) {
		return titles[column];
	}

}
